<template>
  <div>
    <TopFilter :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"      @resetChange="resetHandle"></TopFilter>
    <BaseDialog :visible.sync="visible" :title="'车型选择'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Vehicle @close="close" @save="save"></Vehicle>
    </BaseDialog>
    <!--  服务中心选择 -->
    <BaseDialog :visible.sync="selectDelearFlag" title="服务中心选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerList @close="Delearclose" @save="Delearsave" selectionType="multiple" />
    </BaseDialog>
    <Drawer :visible.sync="visibleEdit" :title="'索赔查看'" destroyOnClose width="100%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <editForm @close="editclose" @save="editsave" :rowData="rowData"></editForm>
    </Drawer>
    <!-- table -->
    <FilterTable height="auto" selectionType="single" ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :dataSource="dataList" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">添加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
  import editForm from '@/pages/claimDemage/BasicData/ClaimQueryFactory/editForm.vue'
  import {
    getClaimListByPage, getModelList
  } from '@/api/usedPartsReturnManage/usedPartsReturn_OEM/usedPartsJF';
  import { getSpList } from '@/api/claim/factory/ClaimQueryFactory/index';
  import Vehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
  import moment from "moment";
  import {  getAppId } from '@/assets/js/auth';
  import { dictionary } from '@/utils/dictMixin';
  import DealerList from '@/pages/claimDemage/tools/DealerList.vue';

export default {
  props: ['ownerCode', 'jfReturnNo'],
  mixins: [dictionary],
  components: {
    Vehicle,
    DealerList,
    editForm
  },
  data() {
    return {
      // single: true,
      rowData: null,
      visibleEdit: false,
      single: false,
      // 非多个禁用
      multiple: true,
      dealerList: [],
      selectDelearFlag: false,
      dealerCompanyCode: [],
      dealerData: [],
      selectDealerData: [],
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchApi: getClaimListByPage,
      fetchParams: {
        ownerCode: this.ownerCode,
        jfReturnNo: this.jfReturnNo,
        xhrAbort: false
      }, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  async created() {
    await this.initModelName();
  },
  methods: {
    //车型名称
    async initModelName() {
      console.log('===== 获取下拉框数据 ====== ');
      const res = await getModelList({ currentPage: 1, pageSize: 99999 });
      console.log('==========', res);
      if (res.resultCode == 200) {
        this.topFilterInit.find(x => x.fieldName == 'modelName').initialValue = '';
        this.topFilterInit.find(x => x.fieldName == 'modelName').itemList = res.data.records.map(y => ({ text: y.modelName, value: y.modelName }));
      }
    },
    editclose() {
      this.visibleEdit = false;
    },
    editsave(val) {
      this.rowData = val;
      this.$emit('claimDetail', val);
      // this.visibleEdit = true;
      // this.closeDialog();
    },
    edit(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '索赔类型', fieldName: 'cmsClaimType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5510',[]) },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '车型名称', fieldName: 'modelName', placeholder: '请选择...', initialValue: '', itemList: [] },
        // { type: 'SELECT', label: '索赔单状态', fieldName: 'claimStatus', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5513', [55131001, 55131004, 55131005, 55131006, 55131007, 55131008]) },
      ]
    },
    resetHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    //搜索获取数据
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, this.fetchParams, val, { claimStatus:55131008,cbFlag:1,xhrAbort: false,dealerCode: this.searchDealerCode, dealerCompanyCode: this.selectDealerData.length ? this.selectDealerData : null });
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // { title: '索赔单状态', dataIndex: 'statusStr', sorter: true },
        {title: '索赔单号', dataIndex: 'claimNo', sorter: true},
        // { title: '索赔单号',
        //   dataIndex: 'claimNo',
        //   sorter: true,
        //   render: props => {
        //     return (
        //       <div style='text-align:center'>
        //         <multiuse-button size='mini' type='text' onClick={() => this.editsave(props.row)}>
        //           {props.row.claimNo}
        //         </multiuse-button>
        //       </div>
        //     );
        //   }
        // },
        { title: '索赔类型', dataIndex: 'cmsClaimTypeStr', sorter: true },
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        { title: '车型名称', dataIndex: 'modelName', sorter: true },
        { title: '旧件数量', dataIndex: 'partCount', sorter: true },
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //服务中心选择页面
    SelectDelear() {
      this.selectDelearFlag = true;
    }, //关闭
    Delearclose() {
      this.selectDelearFlag = false;
    },
    //服务中心选择保存
    Delearsave(obj) {
      console.log('选择数据传递', obj);
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerCompanyCode);
      });
      this.selectDelearFlag = false;
    },
    //保存
    saveDialog() {
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    close() {
      this.visible = false;
    },
    save(obj) {
      this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
      this.visible = false;
    },
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
